package Lintcode;

import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Question: https://www.lintcode.com/zh-cn/old/problem/implement-strstr/
 * Solution:
 * Time: 2018/5/17
 * Coder: Ksxy 
**/
public class ImplementStrstr {
    static Scanner scanner = null;

    static {
        scanner = new Scanner(System.in);
    }

    public static void main(String[] args) {

        String source = scanner.next();
        String target = scanner.next();
        System.out.println(strStr(source, target));
    }

    public static int strStr(String source, String target) {
        // write your code here
        if (source == null || target == null){
            return -1;
        }
        char[] src = source.toCharArray();
        char[] tar = target.toCharArray();
        int index = -1;
        for (int i = 0; i <= src.length - tar.length; i++) {
            int j = 0;
            for (; j < tar.length; j++) {
                if (src[i+j] != tar[j]) break;
            }
            if (j == tar.length) {
                index = i;
                break;
            }
        }
        return index;
    }

    public static int KMP(String source, String target){
        int index = -1;
        return index;
    }

    public static int regular(String source, String target){
        int index = -1;
        Pattern pattern = Pattern.compile(target);
        Matcher result = pattern.matcher(source);
        index = result.start();
        return index;
    }
}
